package com.ims.core.doc.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ims.common.annotation.Log;
import com.ims.common.core.controller.BaseController;
import com.ims.common.core.domain.AjaxResult;
import com.ims.common.enums.BusinessType;
import com.ims.core.doc.domain.TSalOrder;
import com.ims.core.doc.service.ITSalOrderService;
import com.ims.common.utils.poi.ExcelUtil;
import com.ims.common.core.page.TableDataInfo;

/**
 * 销售单Controller
 *
 * @author IMS
 * @date 2024-12-02
 */
@RestController
@RequestMapping("/doc/order")
public class TSalOrderController extends BaseController
{
    @Autowired
    private ITSalOrderService tSalOrderService;

    /**
     * 查询销售单列表
     */
    @PreAuthorize("@ss.hasPermi('doc:order:list')")
    @GetMapping("/list")
    public TableDataInfo list(TSalOrder tSalOrder)
    {
        startPage();
        List<TSalOrder> list = tSalOrderService.selectTSalOrderList(tSalOrder);
        return getDataTable(list);
    }

    /**
     * 导出销售单列表
     */
    @PreAuthorize("@ss.hasPermi('doc:order:export')")
    @Log(title = "销售单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TSalOrder tSalOrder)
    {
        List<TSalOrder> list = tSalOrderService.selectTSalOrderList(tSalOrder);
        ExcelUtil<TSalOrder> util = new ExcelUtil<TSalOrder>(TSalOrder.class);
        util.exportExcel(response, list, "销售单数据");
    }

    /**
     * 获取销售单详细信息
     */
    @PreAuthorize("@ss.hasPermi('doc:order:query')")
    @GetMapping(value = "/{orderNo}")
    public AjaxResult getInfo(@PathVariable("orderNo") String orderNo)
    {
        return success(tSalOrderService.selectTSalOrderByOrderNo(orderNo));
    }

    /**
     * 新增销售单
     */
    @PreAuthorize("@ss.hasPermi('doc:order:add')")
    @Log(title = "销售单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TSalOrder tSalOrder)
    {
        return toAjax(tSalOrderService.insertTSalOrder(tSalOrder));
    }

    /**
     * 修改销售单
     */
    @PreAuthorize("@ss.hasPermi('doc:order:edit')")
    @Log(title = "销售单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TSalOrder tSalOrder)
    {
        return toAjax(tSalOrderService.updateTSalOrder(tSalOrder));
    }

    /**
     * 删除销售单
     */
    @PreAuthorize("@ss.hasPermi('doc:order:remove')")
    @Log(title = "销售单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tSalOrderService.deleteTSalOrderByIds(ids));
    }
}
